﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace Common
{
    public class DGVColumnDefine
    {
        public string CName { get; set; }
        public string CType { get; set; }
        public string CHeadtext { get; set; }
        public int CSort { get; set; }
        public int Width { get; set; }
        public bool ReadOnly { get; set; }

        public static List<DGVColumnDefine> GetListFromXML(string file, string parentNode)
        {
            List<DGVColumnDefine> columnList = new List<DGVColumnDefine>();
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(file);
                XmlElement root = doc.DocumentElement;
                XmlNode tableNode = root.SelectSingleNode(parentNode);

                foreach (XmlNode n in tableNode.ChildNodes)
                {
                    DGVColumnDefine define = new DGVColumnDefine
                    {
                        CName = n.Attributes["name"].Value,
                        CHeadtext = n.Attributes["headtext"].Value,
                        CType = n.Attributes["type"].Value,
                        ReadOnly = Convert.ToBoolean(n.Attributes["readonly"].Value),
                        Width = Convert.ToInt32(n.Attributes["width"].Value),
                        CSort = Convert.ToInt32(n.Attributes["sort"].Value)
                    };
                    columnList.Add(define);
                }
            }
            catch (Exception ex)
            {

                throw(ex);
            }
            
            return columnList;
        }
    }
}
